package com.fg.ihr.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.fg.ihr.domain.Location;
import com.fg.ihr.domain.User;
import com.fg.ihr.repository.LocationRepository;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/location")
public class LocationController {
    private static final Logger logger = LoggerFactory.getLogger(LocationController.class);


    @Autowired
    LocationRepository locationRepository;

    @GetMapping("/list")
    @ResponseBody
    public String getLocationList(
//            @RequestParam Integer page,
//            @RequestParam Integer size
    ){
//        Pageable pageable = PageRequest.of(page - 1, size);
        List<Location> result = locationRepository.findAll();
        JSONArray list = new JSONArray();
        for (Location items:  result) {
            JSONObject map = new JSONObject();
            map.put("text",items.getName());
            map.put("id",items.getId());
            list.add(map);
        }
        String locations = JSON.toJSONString(list);
        return locations;
    }
}
